package com.cqie.tes.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cqie.tes.comm.R;
import com.cqie.tes.comm.qo.BaseQo;
import com.cqie.tes.comm.service.impl.BaseServiceImpl;
import com.cqie.tes.domain.Dept;
import com.cqie.tes.domain.Evalutetarget;
import com.cqie.tes.domain.Evalutetype;
import com.cqie.tes.domain.qo.tes.DeptQo;
import com.cqie.tes.domain.qo.tes.EvalutetargetQo;
import com.cqie.tes.domain.vo.tes.dept.DeptVo;
import com.cqie.tes.domain.vo.tes.evalutetarget.EvalutetargetVo;
import com.cqie.tes.mapper.DeptMapper;
import com.cqie.tes.mapper.EvalutetargetMapper;
import com.cqie.tes.mapper.EvalutetypeMapper;
import com.cqie.tes.service.EvalutetargetService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author DD-GKD
 * @since 2020-09-18
 */
@Service
public class EvalutetargetServiceImpl extends BaseServiceImpl<EvalutetargetMapper, Evalutetarget> implements EvalutetargetService {

    @Autowired
    private EvalutetargetMapper evalutetargetMapper;
    @Autowired
    private EvalutetypeMapper evalutetypeMapper;

    @Override
    public R getList(BaseQo query) {
        EvalutetargetQo qo = (EvalutetargetQo) query;

        List<EvalutetargetVo> voList = new ArrayList<>();
        QueryWrapper<Evalutetarget> fqw = new QueryWrapper<>();
        fqw.eq("mark", 1);
        fqw.orderByAsc("sortCode");
        if (qo.getTypeId() != null){
            fqw.eq("typeId",qo.getTypeId());
        }
        List<Evalutetarget> entityList = evalutetargetMapper.selectList(fqw);

        entityList.forEach(entity -> {
            EvalutetargetVo vo = new EvalutetargetVo();
            BeanUtils.copyProperties(entity,vo);
            voList.add(vo);
        });

        return R.ok().message("查询成功").data("total", voList.size()).data("rows", voList);
    }

    @Override
    public R optionList() {
        return null;
    }
}
